package com.dt.global.web.dao.repquery.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.springframework.stereotype.Repository;

import com.dt.components.exhibernate.impl.HibernateDaoImpl;
import com.dt.global.entitys.bo.TWebCoreArticle;
import com.dt.global.entitys.bo.TWebCoreMien;
import com.dt.global.entitys.bo.TWebLinks;
import com.dt.global.web.dao.Newscentrality.impl.NewscentralityImpl;
import com.dt.global.web.dao.repquery.RepQueryDao;
/**
 * 代表风采的查询的实现类
 * @author WJX
 *
 */
@SuppressWarnings("rawtypes")
@Repository
public class RepQueryDaoImpl extends HibernateDaoImpl implements RepQueryDao {
	private static final Logger LOG = Logger.getLogger(NewscentralityImpl.class);
	public List<TWebCoreMien> getTWebRepQuery(String channelId)
			throws HibernateException {
		try {
			List<String> param = new ArrayList<String>();
//		    String sql="from TWebCoreMien where channelId=? and isDisabled='Y' order by newid()";
		    String sql="from TWebCoreMien where channelId=? and isDisabled='Y'";
		    param.add(channelId);
			@SuppressWarnings("unchecked")
			List<TWebCoreMien> list = this.find(sql,param);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			LOG.error(e);
			return null;
		}
	}
	
	public TWebCoreMien getTWebCoreArticleId(String articleId)
			throws HibernateException {
		try {
			List<String> param = new ArrayList<String>();
			TWebCoreMien article =null;
		    String sql="from TWebCoreMien where articleId=? ";
		    param.add(articleId);
			@SuppressWarnings("unchecked")
			List<TWebCoreMien> list = this.find(sql,param);
			if(list !=null&&list.size()>0){
				article=list.get(0);
			}
			return article;
		} catch (Exception e) {
			e.printStackTrace();
			LOG.error(e);
			return null;
		}
	}

	@Override
	public List<TWebCoreMien> getTWebCoreMienPid(String pid)
			throws HibernateException {
		try {
			List<String> param = new ArrayList<String>();
		    String sql="from TWebCoreMien where channelId in(select channelId from TWebCoreChannel where pid=? ) and isDisabled='Y'";
		    param.add(pid);
			@SuppressWarnings("unchecked")
			List<TWebCoreMien> list = this.find(sql,param);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			LOG.error(e);
			return null;
		}
	}

}
